package com.lagou.task10;
import java.util.Scanner;
public class FiveQi {
    String[][] qipan = new String[17][17];
    String[] arr = {" ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};

    //构造方法,初始化棋盘
    FiveQi(){
        for (int i=0;i<qipan.length;i++){
            for (int j=0;j<qipan[i].length;j++){
                if (0 == i){
                    qipan[i][j] = arr[j];
                }else if(0 == j){
                    qipan[i][j] = arr[i];
                }else {
                    qipan[i][j] = "+";
                }
            }
        }
    }

    //定义成员方法打印棋盘
    public void show(){
        for (int i=0;i<qipan.length;i++){
            for (int j=0;j<qipan[i].length;j++){
                System.out.print(qipan[i][j]+" ");
            }
            System.out.println();
        }
    }

    public void play(){
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        //判断是否获胜继续下棋,在此先不对输入的行和列输入值的合理性做判断
        while(true) {
            System.out.println("请输入黑色落子行(1-16之间)");
            int row = sc.nextInt();
            System.out.println("请输入黑色落子列");
            int line = sc.nextInt();
            qipan[row][line] = "⚫";
            flag = this.judge();
            if (flag==true){
                break;
            }
            System.out.println("请输入白色落子行");
            int row1 = sc.nextInt();
            System.out.println("请输入白色落子行");
            int line1 = sc.nextInt();
            qipan[row1][line1] = "〇";
            flag = this.judge();
            if (flag==true){
                break;
            }
        }
    }

    public Boolean judge(){
        //扫描整个棋盘,对每个落子点的连子数做判断
            for (int i =0;i<qipan.length;i++){
                for (int j = 0;j < qipan[i].length;j++){
                    //分别判断白色和黑色哪方胜利    下面进行黑色旗子的判断
                    if (qipan[i][j] == "⚫"){
                        //注意对对角位置的连子进行判断
                        //1.先进行垂直方向的判断  2. 进行水平方向的判断 3. 进行对角方向的判断
                        int count = 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i][j+m] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }
                        count= 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }
                        count = 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i+m][j+m] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }

                    }else if(qipan[i][j] == "〇"){
                        int count = 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i][j+m] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }
                        count= 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }
                        count = 1;
                        for(int m =1 ; m <= 4;m++){
                            //右边的四个旗子中但凡有一个直接break
                            if (j+m<=qipan.length && qipan[i+m][j+m] == "⚫"){
                                count++ ;
                                if(count == 5){
                                    System.out.println("胜利");
                                    return true;
                                }
                            }/*else if (j+m<=qipan.length && qipan[i+m][j] == "⚫"){ } count会串*/
                        }

                    }
                }
            }
            return false;
    }




}
